-- ==
-- input { 4i64 5i64 [[0,0,0],[0,3,0],[3,4,0]] [[0,0,1],[0,3,4],[1,2,3]] }
-- output {
-- [[[2i32, 1i32, 0i32, 0i32, 0i32],
--   [0i32, 0i32, 0i32, 0i32, 0i32],
--   [0i32, 0i32, 0i32, 0i32, 0i32],
--   [0i32, 0i32, 0i32, 0i32, 0i32]],
--  [[1i32, 0i32, 0i32, 0i32, 1i32],
--   [0i32, 0i32, 0i32, 0i32, 0i32],
--   [0i32, 0i32, 0i32, 0i32, 0i32],
--   [0i32, 0i32, 0i32, 1i32, 0i32]],
--  [[0i32, 0i32, 0i32, 1i32, 0i32],
--   [0i32, 0i32, 0i32, 0i32, 0i32],
--   [0i32, 0i32, 0i32, 0i32, 0i32],
--   [0i32, 1i32, 0i32, 0i32, 0i32]]]
-- }

def main (n: i64) (m: i64) =
  map2 (\xs ys ->
          reduce_by_index_2d (replicate n (replicate m 0))
                             (+)
                             0
                             (zip (map i64.i32 xs) (map i64.i32 ys))
                             (map (const 1) xs))
